package com.example.baseweather.ui.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.baseweather.databinding.RvVideoInfoBinding;
import com.example.baseweather.domain.VideoInfoBean;
import com.example.baseweather.ui.adapter.VideoRecyclerViewAdapter.MyViewHolder;
import com.example.baseweather.ui.inter.ItemClickInterFace;

import java.util.List;

public class VideoRecyclerViewAdapter extends RecyclerView.Adapter<MyViewHolder> {

    private List<VideoInfoBean> list;
    private ItemClickInterFace listener;

    public VideoRecyclerViewAdapter(List<VideoInfoBean> list) {
        this.list = list;
    }

    public void setListener(ItemClickInterFace listener) {
        this.listener = listener;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RvVideoInfoBinding binding = RvVideoInfoBinding.inflate(LayoutInflater.from(parent.getContext()));
        return new MyViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        VideoInfoBean videoInfoBean = list.get(position);
        holder.binding.ivInfo.setImageBitmap(videoInfoBean.getBitmap());
        holder.binding.tvVideoInfo.setText(videoInfoBean.getVideoName());
        holder.binding.tvPlayInfo.setText(videoInfoBean.getPlayInfo());
        holder.binding.videoCard.setOnClickListener(v -> {
            listener.onItemClick(v, position);
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder {

        private RvVideoInfoBinding binding;

        public MyViewHolder(@NonNull RvVideoInfoBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }


    }
}
